package sms

import (
	"errors"
	"net/http"
	"net/url"
)

type SMSModel struct {
	CDKey     string //用户序列号, 3SDK-EMY-0103-JFVRO
	Password  string //用户密码,751271
	Phone     string //手机号码最多200个，多个用英文“,”隔开
	Message   string //短信内容（UTF-8编码），最多500汉字或1000纯英文
	Addserial string //附加号，最长10位，可置空
}

func (sms *SMSModel) Send() error {
	//发送地址 http://sdkhttp.eucp.b2m.cn/sdkproxy/sendsms.action
	params := url.Values{"cdkey": {sms.CDKey}, "password": {sms.Password}, "message": {sms.Message}, "phone": {sms.Phone}, "addserial": {sms.Addserial}}
	resp, err := http.PostForm("http://sdkhttp.eucp.b2m.cn/sdkproxy/sendsms.action", params)
	if err != nil {
		return err
	}
	if resp.StatusCode != http.StatusOK {
		return errors.New("发送短信失败")
	}
	return nil
}
